package org.scboy.coobi;

import org.scboy.coobi.sql.Coobi;
import org.scboy.coobi.sql.factory.EntityFactory;
import org.scboy.coobi.caches.GetSystemConfig;
import org.scboy.coobi.properties.CoobiProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
@ConditionalOnClass(Coobi.class)
@EnableConfigurationProperties(CoobiProperties.class)
@AutoConfigureAfter(value = {DataSourceAutoConfiguration.class})
public class CoobiAutoConfiguration {

	@Autowired
	JdbcTemplate template;
	
	@Autowired
	CoobiProperties properties;
	
    @Bean
    @ConditionalOnMissingBean(Coobi.class)
    public Coobi addCoobi() {
    	InitCoobi.init(template,properties);
		return new Coobi();
	}
    
    @Bean
    public EntityFactory getEntityFactory() {
		return new EntityFactory();
	}
    

	@Bean
	public GetSystemConfig getSysConfig() {
		return new GetSystemConfig();
	}
	
}
